<extend name="Layout/ins_page" />
<block name="content">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Form</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>
</head>
<style>

td{
      margin-top:10px;     
    
}
</style>
<body>
    <div id="form1" >
        <input name="id" class="mini-hidden"  value="{$data.b_id}"/>
        <table cellspacing='10' style="width: 700px; border-spacing:0px 10px;" >
			 <tr>
                <td>
                    <label for="textbox1$text">品牌名称：</label>
                </td>
                <td>
                    <input id="textbox1" id="b_name"  name="b_name"  class="mini-textbox" emptyText="如实填写"  required="true" style="width:350px" value ="{$data.b_name}"/>
                </td>
            </tr>
			
			  <tr>
                <td>
                    <label for="textbox1$text">品牌logo：</label>
                </td>
                <td>
             
		     	   <img id="simg" class="group-picture" width="100px" height="100px" src="{$data.logo}" alt="品牌LOGO" ><br>  
		        	<a href="javascript:;" class="a-upload" onclick="$('#group-picture1').click()" > 选择 </a>
		            <input type="file" id='group-picture1' name="group-picture" id="group-picture1" style="display: none;">  
		  			<input  name="logo" id='logo-input' class="mini-textbox" required="false" width='250px'  value ="{$data.logo}" style="display: none""/> 
                
           
                </td>
            </tr>

            <!--<tr>-->
                <!--<td>-->
                    <!--<label for="textbox1$text">品类(*必填)：</label>-->
                <!--</td>-->
                <!--<td>-->

                    <!--<ul id="tree1" class="mini-tree" url="/SapSupplier/getitemcategorycodeOnlyLevelTwo" style="width:200px;padding:5px;"-->
                        <!--showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"-->
                        <!--showCheckBox="true" checkRecursive="true"-->
                        <!--onbeforenodecheck="onBeforeNodeCheck" allowSelect="false" enableHotTrack="false">-->
                    <!--</ul>-->

                <!--</td>-->
            <!--</tr>-->
			
			 <tr>
                <td>
                    <label for="textbox1$text">行业排名：</label>
                </td>
                <td>
                    <input id="textbox1" id="ranking"  name="ranking" class="mini-textbox" emptyText="如实填写" required="true" style="width:350px" value ="{$data.ranking}"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">年销售额（万）：</label>
                </td>
                <td>
                    <input id="textbox1" id="sales_year"  name="sales_year" class="mini-textbox" emptyText="如实填写" required="true" style="width:350px;"  value ="{$data.sales_year}"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">适合人群：</label>
                </td>
                <td>
                    <input id="textbox1" id="suitable"  name="suitable" class="mini-textbox" placeholder="请根据产品有针对性的判别：
例如：35岁以内年轻白领、年薪15万左右" required="true" style="width:350px"  value ="{$data.suitable}"/><br>请根据产品有针对性的判别：
                    例如：35岁以内年轻白领、年薪15万左右
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">建议渠道：</label>
                </td>
                <td>
                    <input id="textbox1" id="channel"  name="channel" class="mini-textbox" placeholder="公司的所有渠道，例如：广发、交行、浦发积分、大客户集采" required="true" style="width:350px"  value ="{$data.channel}"/><br>公司的所有渠道，例如：广发、交行、浦发积分、大客户集采
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">价格区间：</label>
                </td>
                <td>
                <input id="s_price" name="s_price" class="mini-spinner" required="true" value="{$data.s_price}" minValue="0" maxValue="9999999" />
                    - <input id="e_price" name="e_price" class="mini-spinner" required="true" value="{$data.e_price}" minValue="0" maxValue="9999999" />
                </td>
            </tr>
            
            
             <tr>
                <td>
                    <label for="textbox1$text">推荐理由-授权方面：</label>
                </td>
                <td>
                    <input id="textbox1" id="auth_reason"  name="auth_reason" class="mini-textbox" emptyText="某些渠道唯一或独家等" required="true" style="width:350px"  value ="{$data.auth_reason}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">推荐理由-价格方面：</label>
                </td>
                <td>
                    <input id="textbox1" id="price_reason"  name="price_reason" class="mini-textbox" emptyText="例如厂家直供，同比主流渠道价格等" required="true" style="width:350px"  value ="{$data.price_reason}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">推荐理由-发货方面：</label>
                </td>
                <td>
                    <input id="textbox1" id="shipment_reason"  name="shipment_reason" class="mini-textbox" emptyText="支持代发，无需备货等" required="true" style="width:350px"  value ="{$data.shipment_reason}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">推荐理由-支持方面：</label>
                </td>
                <td>
                    <input id="textbox1" id="support_reason"  name="support_reason" class="mini-textbox" emptyText="例如新款首发独家，上新买一送一，版面费用支持等等" required="true" style="width:350px"  value ="{$data.support_reason}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">推荐理由-其他方面：</label>
                </td>
                <td>
                    <input id="textbox1" id="other_reason"  name="other_reason" class="mini-textbox" emptyText="有优势的都可以提交" required="true" style="width:350px"  value ="{$data.other_reason}"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">相关产品链接：</label>
                </td>
                <td>
                    <input id="textbox1" id="relevant_link"  name="relevant_link" class="mini-textbox" emptyText="线上渠道链接等" required="true" style="width:350px;"  value ="{$data.relevant_link}"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">类似品牌链接：</label>
                </td>
                <td>
                    <input id="textbox1" id="similar_brand_link" name="similar_brand_link" class="mini-textbox" emptyText="同品类行业差不多排名即可" required="true" style="width:350px"  value ="{$data.similar_brand_link}"/>
                </td>
            </tr>
			
			
			    <tr>
                <td>
                    <label for="textbox1$text">龙头（爆款）产品推荐：</label>
                </td>
                <td>
                    <input id="textbox1" id="top_link"  name="top_link" class="mini-textbox" emptyText="产品链接" required="true" style="width:350px"  value ="{$data.top_link}"/>
                </td>
            </tr>
            
            
                <tr>
                <td>
                    <label for="textbox1$text">主流渠道：</label>
                </td>
                <td>
                    <input id="textbox1" id="mainstream_channel"  name="mainstream_channel" class="mini-textbox" emptyText="天猫、唯品会、礼品渠道独家、线下实体店等" required="true" style="width:350px"  value ="{$data.mainstream_channel}"/>
                </td>
            </tr>
            
            
                <tr>
                <td>
                    <label for="textbox1$text">银行渠道销售情况：</label>
                </td>
                <td>
                    <input id="textbox1" id="bank_channel_sales"  name="bank_channel_sales" class="mini-textbox" emptyText="说明在哪些银行销售情况如何" required="false" style="width:350px"  value ="{$data.bank_channel_sales}"/>
                </td>
            </tr>
            
                <tr>
                <td>
                    <label for="textbox1$text">推荐人：</label>
                </td>
                <td>
                    <input id="textbox1" id="recommender"  name="recommender" class="mini-textbox" emptyText="如实填写" required="true" style="width:350px"  value ="{$data.recommender}"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">附件：<br>(*商品毛利表，<br>相关PPT等)</label>
                </td>
                <td>
	                 <div class="uploader" id="uploader_add_file" add_file_id="add_file">
					 <input id="add_file_add_file" class="add_file"  name="attachment" value="{$data.attachment}" style="display: none" >
					 <a id="btn_add_file" href="javascript:;" class="">添加附件</a>
					<ul class="file_list" new_upload="" >
				<?php foreach($data['att'] as $att){?>
					<li class="tbody" id="{$att.md5}" add_file="{$att.code}">
					<div class="loading" style="width: 100%;"></div>
					<div class="data" >
					<span class="del text-center" style='width: 75px'>
                        <if condition="$att.cancelled == 1">

                                            <b style="color: red">已作废</b>

                                            <else/>

                                            <span id="cancelleddoc" name="cancelleddoc">
                                                <a href="javascript:canceldoc({$att.id})">作废</a>
                                            </span>

                                        </if>
                        <a class="link showpic" href='/Uploads/Download/{$att.savepath}{$att.savename}' data='/Uploads/Download/{$att.savepath}{$att.savename}'>查看</a></span>
                        <!--<a class="link del" style="display: inline;">删除</a>-->
					<span class="size text-right">{$att.size} kb</span><span class="auto autocut">{$att.name}</span></div>
					</li>
				<?php }?>
					
					</ul>
				</div> 
                </td>
            </tr>

            <tr>
                <td>
                    备注:
                </td>
                <td>
                    <input style="width:400px;" name="remarkes" id='remarkes' class="mini-textarea" required="true"/>
                </td>
            </tr>
            
			<tr>
                <td>
                    
                </td>
                <td>
				    <br/>
                    <a class='mini-button' onclick="submitForm(1)" >保存</a>
                    <a class='mini-button' onclick="" >取消</a>
                    <!--CloseWindow()-->
                                                          
                    
                </td>
            </tr>

            <if condition=' ($haspermission) '>


                <tr>
                    <td colspan="2" align="center">
                        <a class="mini-button" onclick="review(1)" id='query-bt'
                           style="background-color: #81de81;color: white;width: 100px;height: 30px;line-height: 30px;font-weight: bold;">&nbsp;&nbsp;通过&nbsp;&nbsp;</a>
                        <a class="mini-button" onclick="review(-1)" id='query-bt'
                           style="background-color: #de4c2b;color: white;width: 100px;height: 30px;line-height: 30px;font-weight: bold;">&nbsp;&nbsp;不通过&nbsp;&nbsp;</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="left">
                        <span>操作记录</span>
                        <div id='acc_log'>
                            <ul id='acc-log-ul'></ul>
                        </div>
                    </td>
                </tr>

            </if>
            
        </table>
    </div>
    <script type="text/javascript">
        mini.parse();

        // tree beginning
        //var tree = mini.get("tree1");
        //var nodes = tree.getAllChildNodes(tree.getRootNode());
        //tree.uncheckNodes(nodes);

        <?php
            //echo 'tree.setValue("'.$data['category_code'].'");';
        //echo 'tree.expandPath("'.$firstCategory.'");';
            ?>
        // tree ending

        function submitForm(tag) {
            //提交表单数据
            var form = new mini.Form("#form1");
            form.validate();
            if (form.isValid() == false) return;

            if ($(".uploader .tbody").length > 0)  {
            }
            else {
                mini.alert("必须上传相关附件！");
                return;
            }

            //确认提示
            mini.confirm("确定修改记录？", "确定？",
                function (action) {
                    if (action == "ok") {
                        var data = form.getData();      //获取表单多个控件的数据
                        data.attachment = jQuery('#add_file_add_file').val();
                        var json = mini.encode(data);   //序列化成JSON
                        // get tree value
                        //var tree = mini.get("tree1");
                        //var treeValue = tree.getValue(false);
                        //alert(treeValue);
                        //data.category_code = treeValue;
                        $.ajax({
                            url: "/SapSupplier/dobrandadd",
                            type: "post",
                            data: {data: json},
                            dataType: 'json',
                            success: function (data) {
                                if (data.code >= 0) {
//						 mini.confirm(data.msg+" 是否清空表单?", "清空",
//						            function (action) {
//						                if (action == "ok") {
//						                     form.reset();
//						                }
//						            }
//						        );

                                } else {

                                }
                                mini.alert(data.msg);
                                //CloseWindow();
                            }
                        });
                    } else {
                    }
                });

        }

   function CloseWindow(action) {

       if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
       else window.close();
//	   location.href=document.referrer;
    }


   jQuery('#addinput').click(function(){

	   var authinputlist = jQuery('.authinput');
	   var count =authinputlist.length;

	  var   html ="-><input style='width:90px'  class='mini-textbox authinput' name='auth_chain["+count+"]'>";

	   jQuery('#sqlian').append(html); mini.parse();

	   });





    </script>
    
    
    
    <script>
        $(function(){
            $("#group-picture1").change(function(event) {
                var img=event.target.files[0];
                if(!img){
                    return false;
                }
                if(!(img.type.indexOf('image')==0 && img.type && /\.(?:jpg|png|gif)$/.test(img.name)) ){
                    gritter('图片只能是jpg,gif,png');
                    return false;
                }
                var reader = new FileReader();
                reader.readAsDataURL(img);
                reader.onload = function(e){
                     $.post("/upload.php", {imga:e.target.result},function(ret){
                        if(ret.img!=''){
                            console.log('upload success');
                            document.getElementById('simg').src = ret.picUrl;
                            mini.get('logo-input').setValue(ret.picUrl);

                        }else{
                            console.log('upload fail');
                        }
                    },'json');
                }
            });
        });
    </script>
    
    <script type="text/javascript">

    $(document).ready(function() {
    	var uploaders = {};
    	$('.uploader').each(function() {
    		var uploader, $target, $id;
    		$target = $(this);
    		$id = $target.attr('add_file_id');
    		$btn_id = 'btn_' + $id;
    		$uploader_id = 'uploader_' + $id;

    		settings = {
    			runtimes : 'html5,flash',
    			browse_button : $btn_id, // you can pass in id...
    			container : document.getElementById($uploader_id),
    			url : upload_url,
    			flash_swf_url : app_path + '/Public/Static/plupload/Moxie.swf',
    			filters : {
    				max_file_size : '1000mb'
    			}
    		};

    		uploader = new plupload.Uploader(settings);
    		uploaders[$id] = uploader;

    		function FilesAdded(up, files) {

    			for (var i in files) {
    				var str = JSON.stringify(files);

    				if( files[i].id!=null){

    				html = '<li class="tbody" id="' + files[i].id + '">\n';

    				html += '<div class="loading"></div>\n';
    				html += '<div class="data">\n';

    				html += '<span class="del text-center"><a class="link del">删除</a></span>\n';

    				html += '<span class="size text-right">' + plupload.formatSize(files[i].size) + '</span>';
    				html += '<span class="auto autocut">' + files[i].name + '</span>';
    				html += '</li>';
    				html += '</div>\n';

    				$('#uploader_' + $id + ' .file_list').append(html);
    				}
    			}
    			up.start();
    		}

    		uploader.bind("PostInit", function(up) {
    			if ($(".uploader .tbody").length > 0) {
    				$(".uploader .tbody .loading").css("width", "100%");
    				$(".uploader .thead").show();
    				$(".uploader .tbody").each(function() {
    					id = $(this).attr("filename");
    					filename = $(this).attr("filename");
    					size = $(this).attr("size");
    					file = new plupload.File(id, filename, size);
    					file.status = plupload.DONE;
    					count = uploader.files.length;
    					uploader.files[count] = file;
    					path = 'hhhhhhh';
    				});
    			}
    		});

    		uploader.init();

    		uploader.bind('FilesAdded', FilesAdded);

    		uploader.bind("UploadProgress", function(up, file) {
    			$("#" + file.id).find("a.del").hide();
    			$("#" + file.id).find('.loading').css("width", file.percent + "%");
    		});

    		uploader.bind('FileUploaded', function(up, file, data) {
    			var myObject = eval('(' + data.response + ')');
    			if (myObject.status) {
    				if ($("#add_file_" + $id).length != 0) {
    					$("#add_file_" + $id).val($("#add_file_" + $id).val() + myObject.sid + ";");
    				}
    				$("#" + file.id).attr("add_file", myObject.sid);

    				$new_upload = $("#uploader_" + $id + " .file_list").attr("new_upload");
    				$("#uploader_" + $id + " .file_list").attr("new_upload", $new_upload + myObject.sid + ";");

    				$("#" + file.id).find("a.del").show();
    			} else {
    				ui_alert(myObject.info, function() {
    					$("#" + file.id).remove();
    				});
    			}
    		});
    	});
    });

    window.onbeforeunload = function(e) {
    	e = e || window.event;
    	// For IE and Firefox prior to version 4
    	$new_upload = $(".file_list").attr("new_upload");
    	if ($new_upload !== undefined) {
    		if ($new_upload.length) {
    			if (e) {
    				e.returnValue = '上传的附件将被删除，确定退出吗？';
    			}
    			// For Safari
    			return '上传的附件将被删除，确定退出吗？';
    		}
    	}
    };

    $(document).on("click", ".uploader a.del", function() {
    	$obj = $(this).parents("li");
    	$uploader = $(this).parents('.uploader');
    	ui_confirm("确定要删除吗？", function() {

    		$current_del_file = $obj.attr("add_file");
    		$(".add_file", $uploader).val($(".add_file", $uploader).val().replace($current_del_file + ";", ""));

    		$new_upload = $(".file_list", $uploader).attr("new_upload");
    		$(".file_list", $uploader).attr("new_upload", $new_upload.replace($current_del_file + ";", ""));

    		$obj.remove();
    	});
    });

    //--------------------------------
    function onBeforeNodeCheck(e) {
        var tree = e.sender;
        var node = e.node;
        if (tree.hasChildren(node)) {
            //e.cancel = true;
        }
    }

    </script>

    <script type="text/javascript">

        // 检测备注
        function checkRemarkes() {
            var remarkes = mini.get('remarkes').getValue();
            if (remarkes) {
                return true;
            } else {
                return false;
            }
        }

        // 审批操作
        function review(status) {

            if (checkRemarkes()){}
            else{
                mini.alert("备注必填！");
                return;
            }

            doreview(status);

        }
        function doreview(status) {

            mini.mask({
                el: document.body,
                cls: 'mini-mask-loading',
                html: '保存中...'
            });

            var remarkes = mini.get('remarkes').getValue();
            $.ajax({
                url: "/SapSupplier/review20170706",
                data: {id: <?php echo $data['b_id'];?>, status: status, remarkes: remarkes},
            type: "post",
                success: function (data) {
                if (data == 1) {
                    mini.unmask(document.body);
                    //mini.alert('保存成功!');
                    getlog(<?php echo $data['b_id'];?>);
                    return;
                } else {
                    mini.unmask(document.body);
                    mini.alert(data.msg);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
        }

        // 获取记录
        function getlog(id) {
            $.ajax({
                url: '/SapSupplier/getbrandlog',
                data: {id: id},
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    var loghtml = "";
                    for (var i = 0; i < data.length; i++) {
                        loghtml += "<li>用户:" + data[i].user + ' 审核动作:' + data[i].info + " 时间：" + data[i].ctime + "</li>";
                    }
                    $("#acc-log-ul").html(loghtml);
                }

            })
        }

        getlog(<?php echo $data['b_id'];?>);

        function canceldoc(id) {

            //确认提示
            mini.confirm("确定作废文件？", "确定？",
                function (action) {
                    if (action == "ok") {

                        $.ajax({
                            url: "/SapSupplier/canceldoc",
                            type: "post",
                            data: {id: id},
                            dataType: 'json',
                            success: function (data) {
                                mini.alert(data.msg);
                                //var cancelleddoc = mini.get('cancelleddoc');
                                //cancelleddoc.html('abc');
                                //$("#cancelleddoc").html("<b style=\"color: red\">已作废</b>");
                            }
                        });


                    } else {

                    }
                }
            );

        }
    </script>

</body>
</html>

</block>
<block name="js">
	<script type="text/javascript">
		function save() {
			sendForm("form_data", "{:U('save')}", "{:U('index')}");
		}
	</script>
</block>